package com.example.shopping.user.mapper;



import com.example.shopping.user.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface UserMapper {

    //分页查询用户
    @Select("select * from user limit #{currPage},#{pageSize}")
    List<User> getUserList(@Param("currPage") int currPage, @Param("pageSize") int pageSize);

    //用id查询用户所有
    @Select("select * from user where id=#{uid}")
    List<User> getUseridList(@Param("uid") int uid);

    //添加用户 参数有 用户名称，用户账号，用户密码，邮箱，手机号，角色，状态 ;
//    @Insert("INSERT INTO `user` (`id`, `name`, `account`, `password`, `email`, `phone`,`role`,`staute`) VALUES (null,?,?,?,?,?, ?,?)")
    @Insert("INSERT INTO  user (name, account, password, email, phone,role) VALUES (#{name},#{account},#{password},#{email},#{phone},#{role})")
    int getuser(@Param("name") String name,@Param("account") String account,@Param("password") String password,@Param("email") String email,@Param("phone") String phone,@Param("role") String role);
//    int getuser(User user);
    //修改用户状态
    @Update("update user set staute=#{staute} where id=#{id}")
    int getuserid(@Param("staute") int staute,@Param("id") int id);

//    删除单个用户
        @Delete("delete from user where id=#{id}")
        int getdel(@Param("id") int id);

//    分配用户角色
    @Update("update user set role=#{role} where id=#{id}")
    int getupdaterole(@Param("role") String role,@Param("id") int id);

    //编辑修改用户
    @Update("update user set name=#{name} , account=#{account}, password=#{password}, email=#{email},phone=#{phone} where id=#{id}")
    int getuserupdate(@Param("name") String name,@Param("account") String account,@Param("password") String password,@Param("email") String email,@Param("phone") String phone,@Param("id") int id);

    //查询总条数
    @Select("select count(*) from `user`")
    int getusercount();

    //模糊查询
    @Select("select * from user where name like '%${name}%'")
    List<User> usermohu( @Param("name") String name);
}
